#!/bin/bash

root="../../../"
protoloader_src="${root}examples/protoloader.lua"
protoloader_dst="${root}service/protoloader.lua"
# 拷贝protoloader文件
cp "$protoloader_src" "$protoloader_dst"

gateway_folder="../service/gateway"
if [ ! -d "$gateway_folder" ]; then 
    mkdir -p "$gateway_folder"
fi 

watchdog_folder="../service/gateway/watchdog"
watchdog_init="${watchdog_folder}/init.lua"
if [ -d "$watchdog_folder" ]; then
    if [ ! -f "$watchdog_init" ]; then
        cp "${root}examples/watchdog.lua" "$watchdog_init"
    fi 
else 
    mkdir -p "$watchdog_folder"
    cp "${root}examples/watchdog.lua" "$watchdog_init"
fi

gate_folder="../service/gateway/gate"
gate_init="${gate_folder}/init.lua"
if [ -d "$gate_folder" ]; then
    if [ ! -f "$gate_init" ]; then
        cp "${root}service/gate.lua" "$gate_init"
    fi 
else 
    mkdir -p "$gate_folder"
    cp "${root}service/gate.lua" "$gate_init"
fi

agent_folder="../service/agent"
agent_init="${agent_folder}/init.lua"
if [ -d "$agent_folder" ]; then
    if [ ! -f "$agent_init" ]; then
        cp "${root}examples/agent.lua" "$agent_init"
    fi 
else 
    mkdir -p "$agent_folder"
    cp "${root}examples/agent.lua" "$agent_init"
fi

gateserver_folder="../lualib"
gateserver_init="${gateserver_folder}/gateserver.lua"
if [ -d "$gateserver_folder" ]; then
    if [ ! -f "$gateserver_init" ]; then
        cp "${root}lualib/snax/gateserver.lua" "$gateserver_init"
    fi 
else 
    mkdir -p "$gateserver_folder"
    cp "${root}lualib/snax/gateserver.lua" "$gateserver_init"
fi